package com.ad.pet.message.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ad.pet.R;
import com.ad.pet.common.data.utils.glide.GlideUtil;
import com.ad.pet.models.remote.message.Message;

import java.util.List;

/**
 * Created by SEELE on 2019/6/21.
 */

public class MessageViewAdapter extends BaseQuickAdapter<Message, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MessageViewAdapter(List<Message> data) {
        super(R.layout.item_system_message_bottom_layout,data);

    }

    @Override
    protected void convert(BaseViewHolder helper, Message item) {

        TextView tvTitle = helper.getView(R.id.tvTitle);
        TextView tvNumber = helper.getView(R.id.tv_msg_num);
        ImageView imageView = helper.getView(R.id.iv_icon);
        TextView tvDate = helper.getView(R.id.tv_time);
        TextView tvMsg = helper.getView(R.id.tv_content);


        tvTitle.setText(item.getName());
        tvNumber.setText(String.valueOf(item.getNum()));
//        if (item.getNum()==0){
//            tvNumber.setVisibility(View.GONE);
//        }else {
//            tvNumber.setVisibility(View.VISIBLE);
//        }
        GlideUtil.load(mContext, item.getImg(), imageView);

        if (item.getNum()==0){
            tvNumber.setVisibility(View.GONE);
        }else {
            tvNumber.setVisibility(View.VISIBLE);
        }
            if (TextUtils.isEmpty(item.getLast_msg())) {
                tvMsg.setVisibility(View.GONE);
            } else {
                tvMsg.setVisibility(View.VISIBLE);
            }
            if (TextUtils.isEmpty(item.getLast_time())
                    ) {
                tvDate.setVisibility(View.GONE);
            } else {
                tvDate.setVisibility(View.VISIBLE);
            }

            tvDate.setText(item.getLast_time());
            tvMsg.setText(item.getLast_msg());


    }
}
